package com.qidian.buy.goods.controller;

import com.qidian.buy.goods.entity.Item;
import com.qidian.buy.goods.service.IItemService;
import com.qidian.buy.goods.vo.ItemAndSpeRelationVO;
import com.qidian.buy.goods.vo.ItemVO;
import com.qidian.buy.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author 戴着假发的程序员
 * @since 2024-05-08
 */
@RestController
@RequestMapping("/item")
public class ItemController {
    @Autowired
    private IItemService itemService;

    @GetMapping("/detail")
    public QdResult detail(Long itemId){
        return itemService.detail(itemId);
    }
    @GetMapping("/get")
    public QdResult get(Long itemId){
        return itemService.getByItemId(itemId);
    }

    @GetMapping("/querySpeIdByItemId")
    public QdResult querySpeIdByItemId(Long itemId){
        return itemService.getSpeIdByItemId(itemId);
    }
    @PostMapping("/addItemAndSpeRelation")
    public QdResult addItemAndSpeRelation(@RequestBody ItemAndSpeRelationVO vo){
        return itemService.addItemAndSpeRelation(vo.getItemId(),vo.getSpeId());
    }
    @GetMapping("/list")
    public QdResult list(Item item, @RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "10")int limit){
        return itemService.list(item,page,limit);
    }

    @PostMapping("/save")
    public QdResult save(@RequestBody ItemVO vo){
        //QdResult save = itemService.save(vo);
        return itemService.saveWrapper(vo);
    };
}
